#include <stdio.h>
#define MAX 25

/*	define behavior:
	move: first return all the elemenets above a, then...
		onto: 
			1) return all the elements above b
			2) move a to b
		over: move a to the top of b pile
	pile:
		onto:
			1) return all the elemnts above b
			2) move all above a to b
		over: move all above a to above
	illegal:
		1) a==b
		2) a,b are from the same pile
*/

/*	define data structure:
	pos1[i] the # of pile i is currently at
	pos2[2] the # of element i is, in one pile
	ele[i][j]	i: pile number;	j: element order in this pile;	value: the element number
		-1 means there is no element in this position
*/

/*	define behavior/method:
	int prompt(int cmd[n]);		// prompt & translate the commend to coresponding required one, return 0 if wrong
	return_one_back(int i,j int pos1[], int pos2[], int ele[i][j]);	// return one element back, and update...
	return_all_back(int a, int pos1[], int pos2[], int ele[]);	// return the elements above 'a' back, and update the coresponding array
	move_one_to(int a, int b, int pos1[], int pos2[], int ele[]);	// move a above b, and update the coresponding array
	move_all_to(int a, int b, int pos1[], int pos2[], int ele[]);	// move all the elements above a to b, and update the coresponding array
*/

int prompt(int cmd[]){
	char s1[10],s2[10];
	scanf("%s",s1);
	if(!strcmp(s1,"quit"))	return 0;
	else{
		scanf("%d%s%d",cmd+2,s2,cmd+3);
		if(!strcmp(s1,"move"))	cmd[0]=1;
		else if(!strcmp(s1,"pile"))	cmd[0]=2;
		else {cmd[3]=cmd[2]=-1;};
		if(!strcmp(s2,"onto"))	cmd[1]=1;
		else if(!strcmp(s2,"over"))	cmd[1]=2;
		else {cmd[3]=cmd[2]=-1;}	
	}
	return 1;
}


	void return_one_back(int i,int j, int pos1[], int pos2[], int ele[MAX][])	// return one element back, and update...
	{
		int a=ele[i][j];
		pos1[a]=a;pos2[a]=0;ele[i][j]=-1;ele[a][0]=0;
	}
	void return_all_back(int a, int pos1[], int pos2[], int ele[]);	// return the elements above 'a' back, and update the coresponding array
	void move_one_to(int a, int b, int pos1[], int pos2[], int ele[]);	// move a above b, and update the coresponding array
	void move_all_to(int a, int b, int pos1[], int pos2[], int ele[]);	// move all the elements above a to b, and update the coresponding array

int main(){
	int n;
	int cmd[4];
	
	scanf("%d",&n);
	while(prompt)
	{
		
	}
	
	getch();
	return 0;
}
